from flask import session

from info import redis_store
from info.models import User
from . import index_blue
import logging
from flask import render_template, current_app, jsonify


@index_blue.route("/")
def index():
    user_id = session.get("user_id")
    print(user_id)
    print("bbbbbbbbb")
    user = None
    if user_id:
        try:
            print("cccccccccc")
            user = User.query.get(user_id)
            print("aaaaaaa")
        except Exception as e:
            current_app.logger.error(e)
    data = {
        "user_info": user.to_dict() if user else ""
    }

    return render_template("news/index.html", data=data)


# 处理网站logo
# 获取静态文件资源,是用current_app.send_static_file("文件路径")
@index_blue.route('/favicon.ico')
def web_logo():

    return current_app.send_static_file("news/favicon.ico")

